/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.service;

import com.documents.common.core.PageBean;
import com.documents.common.core.service.BaseSrv;
import com.documents.pojo.Notice;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class NoticeService extends BaseSrv<Notice, Integer> {

    public PageBean getPageBean(int page, int pageSize, Notice type) {
        PageBean pageBean = new PageBean();
        pageBean.setPageSize(pageSize);
        pageBean.setCurrentPage(page);
        String condition = "";
        Object[] parameters = new Object[1];
        int paramIndex = 0;
        if (type != null) {


            if (type.getType() > 0) {
                if (condition.trim().length() == 0) {
                    condition += "type=?";
                } else {
                    condition += "and type=?";
                }

                parameters[paramIndex] = type.getType();
                paramIndex++;
            }
        }
        Long allRow = this.findTotalCount(condition, parameters);
        int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
        pageBean.setAllRow(allRow.intValue());
        pageBean.setTotalPage(totalPage);
        List<Notice> list;
        if (page == 1) {
            list = this.findWithPaging(condition, parameters, "create_time desc", page - 1, pageSize);
        } else {
            list = this.findWithPaging(condition, parameters, "create_time desc", (page - 1) * pageSize, pageSize);
        }

        pageBean.setList(list);

        return pageBean;
    }
    

    public List<Notice> getNoticeListTop(int type) {

        List<Notice> nlist = this.findWithPaging("type=?", new Object[]{type}, "create_time desc", 0, 5);
        return nlist;
    }
}
